/**   
 * @{#} SampleEntity.java Create on 2011-5-25 下午05:38:00   
 *   
 */
package com.psammead.dms.system.sercurity.entity;   

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.psammead.dms.common.core.entity.RemovableEntity;
  
/**   
 * @Title:系统用户实体类
 * @author <a href="mailto:si-qi.liang@hp.com">Liang, Si-Qi</a>  
 * @version 1.0   
 */
@Entity(name = "SysUser")
@Table(name = "tb_sys_user")
@NamedQueries({
	@NamedQuery(name="tb_sys_user.findSysUserByLoginName", 
			query="SELECT u FROM SysUser u WHERE u.loginName = :loginName and u.removed=0")
})
public class SysUser extends RemovableEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5656484812673289479L;

	public SysUser() {
		super();
	}
	/**
	 * static values of user status;
	 */
	public static final long INACTIVE = 0L;
	public static final long NORMAL = 1L;
	public static final long FORBIDDEN = -1L;
	/**
	 * data fields
	 */
	private long id; //primary key of user
	private String loginName; //the username used to login
	private String password;  //the password used to login
	private String actualName;//actual name of the user
	private String title;
	private String telphone;
	private String celphone;
	private String email;
	private SysUser creator;
	private Date createTime;
	
	
	private long status= 0;
	/**
	 * Join Column
	 */
	private Set<SysGroup> groups=new HashSet<SysGroup>();
	

	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="user_id")
	@Override
	public long getId() {
		return id;
	}
	public void setId(long id){
		this.id=id;
	}
	
	@Column(name="login_name", length=32,nullable=false, unique=true)
	public String getLoginName() {
		return loginName;
	}
	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	
	@Column(name="password", length=32)
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	@Column(name="actual_name", length=32)
	public String getActualName() {
		return actualName;
	}
	public void setActualName(String actualName) {
		this.actualName = actualName;
	}
	
	@Column(name="status")
	public long getStatus() {
		return status;
	}
	public void setStatus(long status) {
		this.status = status;
	}
	
	/**
	 * @Title:getGroups
	 * @Desciption: 多对多关联系统角色，SysUser作为被控端
	 * @return
	 */
	@ManyToMany(cascade = CascadeType.REFRESH,mappedBy="users", fetch = FetchType.LAZY)
	public Set<SysGroup> getGroups() {
		return groups;
	}
	public void setGroups(Set<SysGroup> groups) {
		this.groups = groups;
	}
	@Column(name="title", length=32)
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	@Column(name="tel_phone", length=32)
	public String getTelphone() {
		return telphone;
	}
	public void setTelphone(String telphone) {
		this.telphone = telphone;
	}
	@Column(name="cel_phone", length=32)
	public String getCelphone() {
		return celphone;
	}
	public void setCelphone(String celphone) {
		this.celphone = celphone;
	}
	@Column(name="email", length=64)
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="creator")
	public SysUser getCreator() {
		return creator;
	}
	public void setCreator(SysUser creator) {
		this.creator = creator;
	}
	@Column(name="create_time")
	@Temporal(TemporalType.DATE)
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

}
 